/**
 * This JUnit tests aspects about warping to different planets.
 * @author Araya Zaesim
 * @version 1.0
 */

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Before;
import org.junit.Test;

/**
 * @author Araya Zaesim
 * @version 1.0
 */
public class WarpingTest {
	/**
	 * Field player.
	 */
	private Player player;

	/**
	 * Field game.
	 */
	private SpaceTraderGui game;

	/**
	 * Field sys1.
	 */
	private SolarSystem sys1;

	/**
	 * Field sys2.
	 */
	private SolarSystem sys2;

	/**
	 * Field sys3.
	 */
	private SolarSystem sys3;

	/**
	 * Field sys4.
	 */
	private SolarSystem sys4;

	/**
	 * Field universe.
	 */
	private List universe;

	/**
	 * Field playerShip.
	 */
	private SpaceShip playerShip;
	
	/**
	 * toString method.
	
	 * @return String */
	public String toString() {
		return "";
	}
	
	/**
	 * Sets up initial variables before each JUnit is run.
	 */
	@Before
	public void start() {
		game = new SpaceTraderGui();
		player = new Player("TestCase", 16, 0, 0, 0, 1000);
		game.startGame(player);
		universe = game.getUniverse();
		playerShip = player.getShip();
		
		sys1 = (SolarSystem) universe.get(0);
		sys1.setX(0);
		sys1.setY(0);
		
		sys2 = (SolarSystem) universe.get(1);
		sys2.setX(2);
		sys2.setY(2);
		
		sys3 = (SolarSystem) universe.get(2);
		sys3.setX(6);
		sys3.setY(6);
		
		sys4 = (SolarSystem) universe.get(3);
		sys4.setX(12);
		sys4.setY(12);
		
		game.setCurrentSystem(sys1);
	}

	/**
	 * Tests to see if the current system gets updated after warping.
	 */
	@Test
	public void testCurrentSystem() {
		if (game.getCurrentSystem() == null) {
			game.setCurrentSystem(sys1);
		}
		game.updateTargetSystem(sys2);
		game.getBtnWarp().doClick();
		final SolarSystem check = game.getCurrentSystem();
		assertEquals("assertion failed", sys2, check);
	}

	/**
	 * Tests to see if the target system is set to null after warping.
	 */
	@Test
	public void testTargetSystem() {
		if (game.getCurrentSystem() == null) {
			game.setCurrentSystem(sys1);
		}
		game.updateTargetSystem(sys2);
		game.getBtnWarp().doClick();
		final SolarSystem sysTest = game.getTargetSystem();
		assertEquals("assertion failed", null, sysTest);
	}

	/**
	 * Tests to see if fuel was updated after warping.
	 */
	@Test
	public void testUpdateFuel() {
		if (game.getCurrentSystem() == null) {
			game.setCurrentSystem(sys1);
		}
		final int fuelLevelInit = playerShip.getFuel();
		game.updateTargetSystem(sys4);
		game.getBtnWarp().doClick();
		final int fuelLevelFinal = playerShip.getFuel();
		assertTrue("assertion failed", fuelLevelFinal < fuelLevelInit);
	}

	/**
	 * Tests to see if warping to farther planets lowers fuel more than warping closer.
	 */
	@Test
	public void testFuelRanges() {
		if (game.getCurrentSystem() == null) {
			game.setCurrentSystem(sys1);
		}
		final int fuelLevelInit = playerShip.getFuel();
		game.updateTargetSystem(sys3);
		game.getBtnWarp().doClick();
		final int fuelLevelOne = playerShip.getFuel();
		playerShip.setFuel(fuelLevelInit);
		game.setCurrentSystem(sys1);
		game.updateTargetSystem(sys4);
		game.getBtnWarp().doClick();
		final int fuelLevelTwo = playerShip.getFuel();
		assertTrue("assertion failed", fuelLevelTwo < fuelLevelOne);
	}
}
